System.Collections.Generic.List<T> 클래스

이 문서에서는 이 API에 대한 참조 설명서에 대한 추가 설명서를 제공합니다.

클래스는 List<T> 클래스에 해당하는 ArrayList 제네릭입니다. 필요에 따라 크기가 IList<T> 동적으로 증가하는 배열을 사용하여 제네릭 인터페이스를 구현합니다.

또는 AddRange 메서드를 List<T> 사용하여 Add 항목을 추가할 수 있습니다.

클래스는 List<T> 같음 비교자와 순서 비교자를 모두 사용합니다.

  • IndexOfLastIndexOf같은 Contains메서드는 Remove 목록 요소에 대해 같음 비교자를 사용합니다. 형식 T 의 기본 같음 비교자는 다음과 같이 결정됩니다. 형식 T 이 제네릭 인터페이스를 IEquatable<T> 구현하는 경우 같음 비교자는 해당 인터페이스의 메서드이고 Equals(T) , 그렇지 않으면 기본 같음 비교자가 됩니다 Object.Equals(Object).

  • 목록 요소에 대한 순서 비교자와 같은 BinarySearch 메서드를 Sort 사용합니다. 형식 T 에 대한 기본 비교자는 다음과 같이 결정됩니다. 형식 T 이 제네릭 인터페이스를 구현하는 경우 기본 비교자는 해당 인터페이스의 메서드이고CompareTo(T), 그렇지 않으면 형식 T 이 비제너릭 IComparable 인터페이스를 구현하는 경우 기본 비교자는 해당 인터페이스의 메서드입니다 CompareTo(Object)IComparable<T>. 형식 T 이 두 인터페이스를 모두 구현하지 않는 경우 기본 비교자가 없으며 비교자 또는 비교 대리자를 명시적으로 제공해야 합니다.

List<T> 정렬이 보장되지 않습니다. 정렬해야 하는 연산(예: BinarySearch)을 List<T> 수행하기 전에 정렬 List<T> 해야 합니다.

이 컬렉션의 요소는 정수 인덱스로 액세스할 수 있습니다. 이 컬렉션의 인덱스는 0부터 시작합니다.

.NET Framework만 해당: 매우 큰 List<T> 개체의 경우 런타임 환경에서 구성 요소의 <gcAllowVeryLargeObjects> 특성을 설정 enabled 하여 64비트 시스템에서 최대 용량을 20억 요소로 true 늘릴 수 있습니다.

List<T>null 참조 형식에 유효한 값으로 허용되며 중복 요소를 허용합니다.

변경할 수 없는 클래스 버전은 다음을 List<T> 참조하세요 ImmutableList<T>.

성능 고려 사항

둘 다 유사한 기능을 가진 클래스를 ArrayList 사용할 List<T> 지 여부를 결정할 때 클래스는 List<T> 대부분의 경우 더 잘 수행되며 형식이 안전합니다. 클래스 형식에 T 참조 형식을 List<T> 사용하는 경우 두 클래스의 동작은 동일합니다. 그러나 값 형식이 형식 T에 사용되는 경우 구현 및 boxing 문제를 고려해야 합니다.

값 형식이 형식 T에 사용되는 경우 컴파일러는 해당 값 형식에 List<T> 대한 클래스의 구현을 생성합니다. 즉, 요소를 사용할 수 있기 전에 개체의 List<T> 목록 요소를 boxed할 필요가 없으며 약 500개의 목록 요소를 만든 후에는 boxing 목록 요소가 아닌 것으로 저장된 메모리가 클래스 구현을 생성하는 데 사용되는 메모리보다 커집니다.

형식 T 에 사용되는 값 형식이 제네릭 인터페이스를 IEquatable<T> 구현해야 합니다. 그렇지 않은 경우와 같은 Contains 메서드는 영향을 받는 목록 요소의 Object.Equals(Object) 상자를 지정하는 메서드를 호출해야 합니다. 값 형식이 인터페이스를 IComparable 구현하고 소스 코드를 소유하는 경우 제네릭 인터페이스를 구현 IComparable<T> 하여 메서드가 Sort 목록 요소를 boxing하지 못하도록 합니다BinarySearch. 소스 코드를 소유하지 않은 경우 개체와 메서드에 개체를 BinarySearchSort 전달 IComparer<T> 합니다.

클래스를 사용하거나 강력한 형식의 래퍼 컬렉션을 직접 작성하는 대신 클래스의 List<T> 형식별 구현을 사용하는 ArrayList 것이 좋습니다. 구현이 .NET에서 이미 수행하는 작업을 수행해야 하고 .NET 런타임은 구현에서 수행할 수 없는 일반적인 중간 언어 코드와 메타데이터를 공유할 수 있기 때문입니다.

F# 고려 사항

클래스는 List<T> F# 코드에서 자주 사용되지 않습니다. 대신 변경할 수 없는 Singly-linked 목록인 목록이 일반적으로 선호됩니다. F# List 은 순서가 지정되고 변경할 수 없는 일련의 값을 제공하며 기능 스타일 개발에 사용할 수 있도록 지원됩니다. F# List<T> 에서 사용하는 경우 클래스는 일반적으로 F# 목록과의 명명 충돌을 방지하기 위해 형식 약어로 참조 ResizeArray<'T> 됩니다.

예제

다음 예제에서는 간단한 비즈니스 개체 List<T>를 추가, 제거 및 삽입하는 방법을 보여 줍니다.

using System;
using System.Collections.Generic;

// Simple business object. A PartId is used to identify the type of part
// but the part name can change.
public class Part : IEquatable<Part>
{
    public string PartName { get; set; }

    public int PartId { get; set; }

    public override string ToString()
    {
        return "ID: " + PartId + "   Name: " + PartName;
    }
    public override bool Equals(object obj)
    {
        if (obj == null) return false;
        Part objAsPart = obj as Part;
        if (objAsPart == null) return false;
        else return Equals(objAsPart);
    }
    public override int GetHashCode()
    {
        return PartId;
    }
    public bool Equals(Part other)
    {
        if (other == null) return false;
        return (this.PartId.Equals(other.PartId));
    }
    // Should also override == and != operators.
}

public class Example
{
    public static void Main()
    {
        // Create a list of parts.
        List<Part> parts =
        [
            // Add parts to the list.
            new Part() { PartName = "crank arm", PartId = 1234 },
            new Part() { PartName = "chain ring", PartId = 1334 },
            new Part() { PartName = "regular seat", PartId = 1434 },
            new Part() { PartName = "banana seat", PartId = 1444 },
            new Part() { PartName = "cassette", PartId = 1534 },
            new Part() { PartName = "shift lever", PartId = 1634 },
        ];

        // Write out the parts in the list. This will call the overridden ToString method
        // in the Part class.
        Console.WriteLine();
        foreach (Part aPart in parts)
        {
            Console.WriteLine(aPart);
        }

        // Check the list for part #1734. This calls the IEquatable.Equals method
        // of the Part class, which checks the PartId for equality.
        Console.WriteLine("\nContains(\"1734\"): {0}",
        parts.Contains(new Part { PartId = 1734, PartName = "" }));

        // Insert a new item at position 2.
        Console.WriteLine("\nInsert(2, \"1834\")");
        parts.Insert(2, new Part() { PartName = "brake lever", PartId = 1834 });

        //Console.WriteLine();
        foreach (Part aPart in parts)
        {
            Console.WriteLine(aPart);
        }

        Console.WriteLine("\nParts[3]: {0}", parts[3]);

        Console.WriteLine("\nRemove(\"1534\")");

        // This will remove part 1534 even though the PartName is different,
        // because the Equals method only checks PartId for equality.
        parts.Remove(new Part() { PartId = 1534, PartName = "cogs" });

        Console.WriteLine();
        foreach (Part aPart in parts)
        {
            Console.WriteLine(aPart);
        }
        Console.WriteLine("\nRemoveAt(3)");
        // This will remove the part at index 3.
        parts.RemoveAt(3);

        Console.WriteLine();
        foreach (Part aPart in parts)
        {
            Console.WriteLine(aPart);
        }

        /*

         ID: 1234   Name: crank arm
         ID: 1334   Name: chain ring
         ID: 1434   Name: regular seat
         ID: 1444   Name: banana seat
         ID: 1534   Name: cassette
         ID: 1634   Name: shift lever

         Contains("1734"): False

         Insert(2, "1834")
         ID: 1234   Name: crank arm
         ID: 1334   Name: chain ring
         ID: 1834   Name: brake lever
         ID: 1434   Name: regular seat
         ID: 1444   Name: banana seat
         ID: 1534   Name: cassette
         ID: 1634   Name: shift lever

         Parts[3]: ID: 1434   Name: regular seat

         Remove("1534")

         ID: 1234   Name: crank arm
         ID: 1334   Name: chain ring
         ID: 1834   Name: brake lever
         ID: 1434   Name: regular seat
         ID: 1444   Name: banana seat
         ID: 1634   Name: shift lever

         RemoveAt(3)

         ID: 1234   Name: crank arm
         ID: 1334   Name: chain ring
         ID: 1834   Name: brake lever
         ID: 1444   Name: banana seat
         ID: 1634   Name: shift lever


     */
    }
}

' Simple business object. A PartId is used to identify the type of part 
' but the part name can change. 
Public Class Part
    Implements IEquatable(Of Part)
    Public Property PartName() As String
        Get
            Return m_PartName
        End Get
        Set(value As String)
            m_PartName = value
        End Set
    End Property
    Private m_PartName As String

    Public Property PartId() As Integer
        Get
            Return m_PartId
        End Get
        Set(value As Integer)
            m_PartId = value
        End Set
    End Property
    Private m_PartId As Integer

    Public Overrides Function ToString() As String
        Return "ID: " & PartId & "   Name: " & PartName
    End Function
    Public Overrides Function Equals(obj As Object) As Boolean
        If obj Is Nothing Then
            Return False
        End If
        Dim objAsPart As Part = TryCast(obj, Part)
        If objAsPart Is Nothing Then
            Return False
        Else
            Return Equals(objAsPart)
        End If
    End Function
    Public Overrides Function GetHashCode() As Integer
        Return PartId
    End Function
    Public Overloads Function Equals(other As Part) As Boolean _
        Implements IEquatable(Of Part).Equals
        If other Is Nothing Then
            Return False
        End If
        Return (Me.PartId.Equals(other.PartId))
    End Function
    ' Should also override == and != operators.

End Class
Public Class Example
    Public Shared Sub Main()
        ' Create a list of parts.
        Dim parts As New List(Of Part)()

        ' Add parts to the list.
        parts.Add(New Part() With {
             .PartName = "crank arm",
             .PartId = 1234
        })
        parts.Add(New Part() With {
             .PartName = "chain ring",
             .PartId = 1334
        })
        parts.Add(New Part() With {
             .PartName = "regular seat",
             .PartId = 1434
        })
        parts.Add(New Part() With {
             .PartName = "banana seat",
             .PartId = 1444
        })
        parts.Add(New Part() With {
             .PartName = "cassette",
             .PartId = 1534
        })
        parts.Add(New Part() With {
             .PartName = "shift lever",
             .PartId = 1634
        })



        ' Write out the parts in the list. This will call the overridden ToString method
        ' in the Part class.
        Console.WriteLine()
        For Each aPart As Part In parts
            Console.WriteLine(aPart)
        Next


        ' Check the list for part #1734. This calls the IEquatable.Equals method
        ' of the Part class, which checks the PartId for equality.
        Console.WriteLine(vbLf & "Contains(""1734""): {0}", parts.Contains(New Part() With {
             .PartId = 1734,
             .PartName = ""
        }))

        ' Insert a new item at position 2.
        Console.WriteLine(vbLf & "Insert(2, ""1834"")")
        parts.Insert(2, New Part() With {
             .PartName = "brake lever",
             .PartId = 1834
        })


        'Console.WriteLine();
        For Each aPart As Part In parts
            Console.WriteLine(aPart)
        Next

        Console.WriteLine(vbLf & "Parts[3]: {0}", parts(3))

        Console.WriteLine(vbLf & "Remove(""1534"")")

        ' This will remove part 1534 even though the PartName is different,
        ' because the Equals method only checks PartId for equality.
        parts.Remove(New Part() With {
             .PartId = 1534,
             .PartName = "cogs"
        })

        Console.WriteLine()
        For Each aPart As Part In parts
            Console.WriteLine(aPart)
        Next

        Console.WriteLine(vbLf & "RemoveAt(3)")
        ' This will remove part at index 3.
        parts.RemoveAt(3)

        Console.WriteLine()
        For Each aPart As Part In parts
            Console.WriteLine(aPart)
        Next
    End Sub
    '
    '        This example code produces the following output:
    '        ID: 1234   Name: crank arm
    '        ID: 1334   Name: chain ring
    '        ID: 1434   Name: regular seat
    '        ID: 1444   Name: banana seat
    '        ID: 1534   Name: cassette
    '        ID: 1634   Name: shift lever
    '
    '        Contains("1734"): False
    '
    '        Insert(2, "1834")
    '        ID: 1234   Name: crank arm
    '        ID: 1334   Name: chain ring
    '        ID: 1834   Name: brake lever
    '        ID: 1434   Name: regular seat
    '        ID: 1444   Name: banana seat
    '        ID: 1534   Name: cassette
    '        ID: 1634   Name: shift lever
    '
    '        Parts[3]: ID: 1434   Name: regular seat
    '
    '        Remove("1534")
    '
    '        ID: 1234   Name: crank arm
    '        ID: 1334   Name: chain ring
    '        ID: 1834   Name: brake lever
    '        ID: 1434   Name: regular seat
    '        ID: 1444   Name: banana seat
    '        ID: 1634   Name: shift lever
    '   '
    '        RemoveAt(3)
    '
    '        ID: 1234   Name: crank arm
    '        ID: 1334   Name: chain ring
    '        ID: 1834   Name: brake lever
    '        ID: 1444   Name: banana seat
    '        ID: 1634   Name: shift lever
    '        

End Class

// Simple business object. A PartId is used to identify the type of part  
// but the part name can change.  
[<CustomEquality; NoComparison>]
type Part = { PartId : int ; mutable PartName : string } with
    override this.GetHashCode() = hash this.PartId
    override this.Equals(other) =
        match other with
        | :? Part as p -> this.PartId = p.PartId
        | _ -> false
    override this.ToString() = sprintf "ID: %i   Name: %s" this.PartId this.PartName

[<EntryPoint>]
let main argv = 
    // We refer to System.Collections.Generic.List<'T> by its type 
    // abbreviation ResizeArray<'T> to avoid conflicts with the F# List module.    
    // Note: In F# code, F# linked lists are usually preferred over
    // ResizeArray<'T> when an extendable collection is required.
    let parts = ResizeArray<_>()
    parts.Add({PartName = "crank arm" ; PartId = 1234})
    parts.Add({PartName = "chain ring"; PartId = 1334 })
    parts.Add({PartName = "regular seat"; PartId = 1434 })
    parts.Add({PartName = "banana seat"; PartId = 1444 })
    parts.Add({PartName = "cassette"; PartId = 1534 })
    parts.Add({PartName = "shift lever"; PartId = 1634 })

    // Write out the parts in the ResizeArray.  This will call the overridden ToString method
    // in the Part type
    printfn ""
    parts |> Seq.iter (fun p -> printfn "%O" p)

    // Check the ResizeArray for part #1734. This calls the IEquatable.Equals method 
    // of the Part type, which checks the PartId for equality.    
    printfn "\nContains(\"1734\"): %b" (parts.Contains({PartId=1734; PartName=""}))
    
    // Insert a new item at position 2.
    printfn "\nInsert(2, \"1834\")"
    parts.Insert(2, { PartName = "brake lever"; PartId = 1834 })

    // Write out all parts
    parts |> Seq.iter (fun p -> printfn "%O" p)

    printfn "\nParts[3]: %O" parts.[3]

    printfn "\nRemove(\"1534\")"
    // This will remove part 1534 even though the PartName is different, 
    // because the Equals method only checks PartId for equality.
    // Since Remove returns true or false, we need to ignore the result
    parts.Remove({PartId=1534; PartName="cogs"}) |> ignore

    // Write out all parts
    printfn ""
    parts |> Seq.iter (fun p -> printfn "%O" p)

    printfn "\nRemoveAt(3)"
    // This will remove the part at index 3.
    parts.RemoveAt(3)

    // Write out all parts
    printfn ""
    parts |> Seq.iter (fun p -> printfn "%O" p)

    0 // return an integer exit code

다음 예제에서는 문자열 형식의 제네릭 클래스의 여러 속성과 메서드를 List<T> 보여 줍니다. (복합 형식의 예는 List<T> 메서드를 Contains 참조하세요.)

매개 변수가 없는 생성자는 기본 용량을 사용하여 문자열 목록을 만드는 데 사용됩니다. 속성 Capacity 이 표시되고 메서드를 Add 사용하여 여러 항목을 추가합니다. 항목이 나열되고 Capacity 속성이 속성과 Count 함께 다시 표시되어 필요에 따라 용량이 증가했음을 표시합니다.

Contains 메서드는 목록에 항목이 있는지 테스트하는 데 사용되고, Insert 메서드는 목록 중간에 새 항목을 삽입하는 데 사용되며, 목록의 내용이 다시 표시됩니다.

기본 Item[] 속성(C#의 인덱서)은 항목을 검색하는 데 사용되고, Remove 메서드는 이전에 추가된 중복 항목의 첫 번째 인스턴스를 제거하는 데 사용되며, 내용이 다시 표시됩니다. 메서드는 Remove 항상 발생한 첫 번째 인스턴스를 제거합니다.

TrimExcess 메서드는 개수와 일치하는 용량을 줄이는 데 사용되며 Capacity 속성과 Count 속성이 표시됩니다. 사용하지 않는 용량이 총 용량의 10% 미만이면 목록의 크기가 조정되지 않았을 것입니다.

마지막으로 이 Clear 메서드는 목록에서 모든 항목을 제거하는 데 사용되며 Capacity 속성과 Count 속성이 표시됩니다.

List<string> dinosaurs = new List<string>();

Console.WriteLine("\nCapacity: {0}", dinosaurs.Capacity);

dinosaurs.Add("Tyrannosaurus");
dinosaurs.Add("Amargasaurus");
dinosaurs.Add("Mamenchisaurus");
dinosaurs.Add("Deinonychus");
dinosaurs.Add("Compsognathus");
Console.WriteLine();
foreach (string dinosaur in dinosaurs)
{
    Console.WriteLine(dinosaur);
}

Console.WriteLine("\nCapacity: {0}", dinosaurs.Capacity);
Console.WriteLine("Count: {0}", dinosaurs.Count);

Console.WriteLine("\nContains(\"Deinonychus\"): {0}",
    dinosaurs.Contains("Deinonychus"));

Console.WriteLine("\nInsert(2, \"Compsognathus\")");
dinosaurs.Insert(2, "Compsognathus");

Console.WriteLine();
foreach (string dinosaur in dinosaurs)
{
    Console.WriteLine(dinosaur);
}

// Shows accessing the list using the Item property.
Console.WriteLine("\ndinosaurs[3]: {0}", dinosaurs[3]);

Console.WriteLine("\nRemove(\"Compsognathus\")");
dinosaurs.Remove("Compsognathus");

Console.WriteLine();
foreach (string dinosaur in dinosaurs)
{
    Console.WriteLine(dinosaur);
}

dinosaurs.TrimExcess();
Console.WriteLine("\nTrimExcess()");
Console.WriteLine("Capacity: {0}", dinosaurs.Capacity);
Console.WriteLine("Count: {0}", dinosaurs.Count);

dinosaurs.Clear();
Console.WriteLine("\nClear()");
Console.WriteLine("Capacity: {0}", dinosaurs.Capacity);
Console.WriteLine("Count: {0}", dinosaurs.Count);

/* This code example produces the following output:

Capacity: 0

Tyrannosaurus
Amargasaurus
Mamenchisaurus
Deinonychus
Compsognathus

Capacity: 8
Count: 5

Contains("Deinonychus"): True

Insert(2, "Compsognathus")

Tyrannosaurus
Amargasaurus
Compsognathus
Mamenchisaurus
Deinonychus
Compsognathus

dinosaurs[3]: Mamenchisaurus

Remove("Compsognathus")

Tyrannosaurus
Amargasaurus
Mamenchisaurus
Deinonychus
Compsognathus

TrimExcess()
Capacity: 5
Count: 5

Clear()
Capacity: 5
Count: 0
 */
Public Class Example2

    Public Shared Sub Main()
        Dim dinosaurs As New List(Of String)

        Console.WriteLine(vbLf & "Capacity: {0}", dinosaurs.Capacity)

        dinosaurs.Add("Tyrannosaurus")
        dinosaurs.Add("Amargasaurus")
        dinosaurs.Add("Mamenchisaurus")
        dinosaurs.Add("Deinonychus")
        dinosaurs.Add("Compsognathus")

        Console.WriteLine()
        For Each dinosaur As String In dinosaurs
            Console.WriteLine(dinosaur)
        Next

        Console.WriteLine(vbLf & "Capacity: {0}", dinosaurs.Capacity)
        Console.WriteLine("Count: {0}", dinosaurs.Count)

        Console.WriteLine(vbLf & "Contains(""Deinonychus""): {0}",
            dinosaurs.Contains("Deinonychus"))

        Console.WriteLine(vbLf & "Insert(2, ""Compsognathus"")")
        dinosaurs.Insert(2, "Compsognathus")

        Console.WriteLine()
        For Each dinosaur As String In dinosaurs
            Console.WriteLine(dinosaur)
        Next
        ' Shows how to access the list using the Item property.
        Console.WriteLine(vbLf & "dinosaurs(3): {0}", dinosaurs(3))
        Console.WriteLine(vbLf & "Remove(""Compsognathus"")")
        dinosaurs.Remove("Compsognathus")

        Console.WriteLine()
        For Each dinosaur As String In dinosaurs
            Console.WriteLine(dinosaur)
        Next

        dinosaurs.TrimExcess()
        Console.WriteLine(vbLf & "TrimExcess()")
        Console.WriteLine("Capacity: {0}", dinosaurs.Capacity)
        Console.WriteLine("Count: {0}", dinosaurs.Count)

        dinosaurs.Clear()
        Console.WriteLine(vbLf & "Clear()")
        Console.WriteLine("Capacity: {0}", dinosaurs.Capacity)
        Console.WriteLine("Count: {0}", dinosaurs.Count)
    End Sub
End Class

' This code example produces the following output:
'
'Capacity: 0
'
'Tyrannosaurus
'Amargasaurus
'Mamenchisaurus
'Deinonychus
'Compsognathus
'
'Capacity: 8
'Count: 5
'
'Contains("Deinonychus"): True
'
'Insert(2, "Compsognathus")
'
'Tyrannosaurus
'Amargasaurus
'Compsognathus
'Mamenchisaurus
'Deinonychus
'Compsognathus
'
'dinosaurs(3): Mamenchisaurus
'
'Remove("Compsognathus")
'
'Tyrannosaurus
'Amargasaurus
'Mamenchisaurus
'Deinonychus
'Compsognathus
'
'TrimExcess()
'Capacity: 5
'Count: 5
'
'Clear()
'Capacity: 5
'Count: 0

[<EntryPoint>]
let main argv = 
    // We refer to System.Collections.Generic.List<'T> by its type 
    // abbreviation ResizeArray<'T> to avoid conflict with the List module.    
    // Note: In F# code, F# linked lists are usually preferred over
    // ResizeArray<'T> when an extendable collection is required.
    let dinosaurs = ResizeArray<_>()
 
    // Write out the dinosaurs in the ResizeArray.
    let printDinosaurs() =
        printfn ""
        dinosaurs |> Seq.iter (fun p -> printfn "%O" p) 
 
    
    printfn "\nCapacity: %i" dinosaurs.Capacity
 
    dinosaurs.Add("Tyrannosaurus")
    dinosaurs.Add("Amargasaurus")
    dinosaurs.Add("Mamenchisaurus")
    dinosaurs.Add("Deinonychus")
    dinosaurs.Add("Compsognathus")
 
    printDinosaurs()
 
    printfn "\nCapacity: %i" dinosaurs.Capacity
    printfn "Count: %i" dinosaurs.Count
 
    printfn "\nContains(\"Deinonychus\"): %b" (dinosaurs.Contains("Deinonychus"))
 
    printfn "\nInsert(2, \"Compsognathus\")"
    dinosaurs.Insert(2, "Compsognathus")
 
    printDinosaurs()
 
    // Shows accessing the list using the Item property.
    printfn "\ndinosaurs[3]: %s" dinosaurs.[3]
 
    printfn "\nRemove(\"Compsognathus\")"
    dinosaurs.Remove("Compsognathus") |> ignore
 
    printDinosaurs()
 
    dinosaurs.TrimExcess()
    printfn "\nTrimExcess()"
    printfn "Capacity: %i" dinosaurs.Capacity
    printfn "Count: %i" dinosaurs.Count
 
    dinosaurs.Clear()
    printfn "\nClear()"
    printfn "Capacity: %i" dinosaurs.Capacity
    printfn "Count: %i" dinosaurs.Count
 
    0 // return an integer exit code
 
    (* This code example produces the following output:
 
Capacity: 0
 
Tyrannosaurus
Amargasaurus
Mamenchisaurus
Deinonychus
Compsognathus
 
Capacity: 8
Count: 5
 
Contains("Deinonychus"): true
 
Insert(2, "Compsognathus")
 
Tyrannosaurus
Amargasaurus
Compsognathus
Mamenchisaurus
Deinonychus
Compsognathus
 
dinosaurs[3]: Mamenchisaurus
 
Remove("Compsognathus")
 
Tyrannosaurus
Amargasaurus
Mamenchisaurus
Deinonychus
Compsognathus
 
TrimExcess()
Capacity: 5
Count: 5
 
Clear()
Capacity: 5
Count: 0
    *)